package com.leesche.zcsp.node.utils.web;

import java.io.Serializable;

/**
 * Created by kaider on 2016/9/21.
 */
public class PagingCondition implements Serializable
{
    protected Integer page = 0;        //第几页
    protected Integer rows = 10;       //每页多少条记录

    // 是否查询所有，设置为true 忽略page 跟 rows
    protected boolean queryAll = false;

    /**
     * <p>Constructor for PagingCondition.</p>
     */
    public PagingCondition() { }

    /**
     * <p>Constructor for PagingCondition.</p>
     *
     * @param page a {@link java.lang.Integer} object.
     * @param limit a {@link java.lang.Integer} object.
     */
    public PagingCondition(Integer page, Integer limit)
    {
        this.page = page;
        this.rows = limit;
    }

    /**
     * <p>Getter for the field <code>page</code>.</p>
     *
     * @return a {@link java.lang.Integer} object.
     */
    public Integer getPage()
    {
        if(page == null){page = 1;}
        return (page - 1) * rows;
    }

    /**
     * <p>Setter for the field <code>page</code>.</p>
     *
     * @param page a {@link java.lang.Integer} object.
     */
    public void setPage(Integer page)
    {
        this.page = page;
    }

    /**
     * <p>Getter for the field <code>rows</code>.</p>
     *
     * @return a {@link java.lang.Integer} object.
     */
    public Integer getRows()
    {
        return rows;
    }

    /**
     * <p>Setter for the field <code>rows</code>.</p>
     *
     * @param rows a {@link java.lang.Integer} object.
     */
    public void setRows(Integer rows)
    {
        this.rows = rows;
    }

    public boolean isQueryAll() {
        return queryAll;
    }

    public void setQueryAll(boolean queryAll) {
        this.queryAll = queryAll;
    }

    /** {@inheritDoc} */
    @Override
    public String toString()
    {
        return "PagingCondition{" +
                "page=" + page +
                ", rows=" + rows +
                '}';
    }
}
